import { Router, Route, Switch, Redirect } from 'react-router-dom'
import { customHistory } from './utils/history'
import { Layout } from '@/pages/Layout/Layout'
import { Login } from '@/pages/Login/Login'
import { ProfileEdit } from '@/pages/Edit/ProfileEdit'
import HOC from './pages/HOC/App'
import { isAuth } from '@/utils/token'

import './App.css'

function App() {
  const authRoute = () => {
    // 判断用户是否登录
    const isLogin = isAuth()
    if (isLogin) {
      return <ProfileEdit />
    } else {
      // 重定向到登录也
      return (
        <Redirect
          to={{
            pathname: '/login',
            state: {
              from: customHistory.location.pathname
            }
          }}
        />
      )
    }
  }
  return (
    <Router history={customHistory}>
      <div className="App">
        <Switch>
          <Route exact path={'/'} render={() => <Redirect to={'/layout'} />} />
          <Route path="/layout" component={Layout} />
          <Route path="/login" component={Login} />
          <Route path="/edit/user" component={ProfileEdit} />
          <Route path={'/hoc'} component={HOC} />
          {/* <Route path="/edit/user" component={authRoute} /> */}
        </Switch>
      </div>
    </Router>
  )
}

export default App
